<html>
<head><meta charset="utf-8"><title>SIMD alignment · project-portable-simd · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/index.html">project-portable-simd</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html">SIMD alignment</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240360470"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240360470" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240360470">(May 26 2021 at 17:26)</a>:</h4>
<p>also I did some reading and AltiVec apparently heavily penalizes unaligned loads because it handles unaligned loads in the simplest way.<br>
you'll never guess what the simplest way is! :D</p>



<a name="240360508"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240360508" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240360508">(May 26 2021 at 17:26)</a>:</h4>
<p>it's really quite elegant! :D</p>



<a name="240360522"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240360522" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240360522">(May 26 2021 at 17:26)</a>:</h4>
<p><strong>truncation</strong></p>



<a name="240360594"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240360594" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240360594">(May 26 2021 at 17:27)</a>:</h4>
<p>no trap on alignment failures! :D</p>



<a name="240360628"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240360628" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240360628">(May 26 2021 at 17:27)</a>:</h4>
<p>all reads perform at the same speed! :D</p>



<a name="240360755"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240360755" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240360755">(May 26 2021 at 17:28)</a>:</h4>
<p>you just uh, have to read twice if you do an unaligned read</p>



<a name="240362127"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240362127" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240362127">(May 26 2021 at 17:39)</a>:</h4>
<p>This doesn't actually matter much for people who aren't coding against a PS3 as later POWER versions now support unaligned loads at normal speed (so, still penalized, but only a "normal" amount instead of 200%).</p>
<p>But anyways the numbers I cited were actually <strong>for</strong> memcpy.</p>



<a name="240362283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240362283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240362283">(May 26 2021 at 17:40)</a>:</h4>
<p>and the 50% was basically the worst case where someone managed to try really hard to find the pathological behavior.</p>



<a name="240362350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240362350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240362350">(May 26 2021 at 17:41)</a>:</h4>
<p>Yeah. I think the best way to go is do what makes sense for your algorithm</p>



<a name="240362362"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240362362" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240362362">(May 26 2021 at 17:41)</a>:</h4>
<p><a href="https://lemire.me/blog/2012/05/31/data-alignment-for-speed-myth-or-reality/">https://lemire.me/blog/2012/05/31/data-alignment-for-speed-myth-or-reality/</a></p>



<a name="240362629"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240362629" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240362629">(May 26 2021 at 17:43)</a>:</h4>
<p>But for our case, my question is which alignments we're actually <strong>worried</strong> about</p>



<a name="240362662"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240362662" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240362662">(May 26 2021 at 17:43)</a>:</h4>
<p>my understanding is that, in all of these cases, the read is aligned to the <strong>element</strong> size</p>



<a name="240362917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240362917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240362917">(May 26 2021 at 17:45)</a>:</h4>
<p>Yes, I think minimum we assume element alignment</p>



<a name="240363023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240363023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240363023">(May 26 2021 at 17:46)</a>:</h4>
<p>Though I'm not actually sure there's much of a difference between the elements being aligned vs unaligned</p>



<a name="240363079"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240363079" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240363079">(May 26 2021 at 17:46)</a>:</h4>
<p>Integers definitely don't need to be aligned to the element either</p>



<a name="240363147"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240363147" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240363147">(May 26 2021 at 17:47)</a>:</h4>
<p>Well it's probably a logic error unless they're reading raw bytes.</p>



<a name="240363892"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240363892" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240363892">(May 26 2021 at 17:52)</a>:</h4>
<p>Agreed</p>



<a name="240367968"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240367968" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240367968">(May 26 2021 at 18:21)</a>:</h4>
<p>So I would like to worry a lot about element alignment and <strong>almost</strong> not at all about vector alignment.<br>
And worry most about ergonomics.</p>



<a name="240368497"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240368497" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240368497">(May 26 2021 at 18:24)</a>:</h4>
<p>Agreed, I think</p>



<a name="240374949"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240374949" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jacob Lifshay <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240374949">(May 26 2021 at 19:06)</a>:</h4>
<p>SimpleV will have a speed advantage for things aligned to element size or bigger</p>



<a name="240406094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406094">(May 26 2021 at 23:55)</a>:</h4>
<p>I'm thinking we may want to provide a function that is like <code>align_to</code> but safe</p>



<a name="240406100"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406100" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406100">(May 26 2021 at 23:55)</a>:</h4>
<p>Since we know the transmute is valid</p>



<a name="240406163"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406163" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406163">(May 26 2021 at 23:56)</a>:</h4>
<p>That's strictly just for convenience though</p>



<a name="240406171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406171">(May 26 2021 at 23:56)</a>:</h4>
<p>honestly the align_to-style is often a bad pattern for simd. You usually want to do the first and last elements with a read_unaligned, and handle the overlap somehow</p>



<a name="240406208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406208">(May 26 2021 at 23:57)</a>:</h4>
<p>typiclally way more efficient than handling the unaligned head/tail with separate loops</p>



<a name="240406393"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406393" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406393">(May 27 2021 at 00:00)</a>:</h4>
<p>Yeah, I ran into that in the past as well</p>



<a name="240406417"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406417" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406417">(May 27 2021 at 00:01)</a>:</h4>
<p>It doesn't work if you want to reprocess overlapping elements to get a full vector</p>



<a name="240406434"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406434" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406434">(May 27 2021 at 00:01)</a>:</h4>
<p>But align_to can still be used in that case to determine the alignment</p>



<a name="240406510"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406510" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406510">(May 27 2021 at 00:02)</a>:</h4>
<p>sort of. note that align_to is allowed to return the full slice in the first element, and under miri it will (actually, maybe this has been changed)</p>



<a name="240406532"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406532" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406532">(May 27 2021 at 00:03)</a>:</h4>
<p>:/</p>



<a name="240406536"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406536" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Caleb Zulawski <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406536">(May 27 2021 at 00:03)</a>:</h4>
<p>Hopefully fixed</p>



<a name="240406684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406684">(May 27 2021 at 00:05)</a>:</h4>
<p>It's pretty fundamental that MIRI doesn't ever treat anything as overaligned, though, AFAIK.  It <em>can't</em> know how to align a <code>[u8; N].align_to::&lt;u16&gt;()</code> (unless maybe that <code>[u8]</code> came from something like a <code>[u32]</code> originally).</p>



<a name="240406770"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406770" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406770">(May 27 2021 at 00:07)</a>:</h4>
<p>i think that's not true. iirc it treats allocations as initially aligned to 8 bytes or something</p>



<a name="240406837"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406837" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406837">(May 27 2021 at 00:08)</a>:</h4>
<p>I don't see why it should.  <code>GlobalAlloc</code> doesn't promise that.  And even if it does for allocations, I don't see why it would apply to local variables, say.</p>



<a name="240406849"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406849" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406849">(May 27 2021 at 00:08)</a>:</h4>
<p>i think it was a concession to how much code being strict about it broke</p>



<a name="240406857"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406857" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406857">(May 27 2021 at 00:08)</a>:</h4>
<p><span class="user-mention" data-user-id="120791">@RalfJ</span> might be around to confirm or correct</p>



<a name="240406960"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406960" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406960">(May 27 2021 at 00:10)</a>:</h4>
<p>I guess it depends on <code>-Zmiri-disable-alignment-check</code> and <code>-Zmiri-symbolic-alignment-check</code> and such.</p>



<a name="240406963"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240406963" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240406963">(May 27 2021 at 00:10)</a>:</h4>
<p><span class="user-mention silent" data-user-id="125270">scottmcm</span> <a href="#narrow/stream/257879-project-portable-simd/topic/Porting.20benchamark.20examples/near/240406684">said</a>:</p>
<blockquote>
<p>It <em>can't</em> know how to align a <code>[u8; N].align_to::&lt;u16&gt;()</code> (unless maybe that <code>[u8]</code> came from something like a <code>[u32]</code> originally).</p>
</blockquote>
<p>Part of the frustrating thing about this function is that IMO a "correct" implementation of, say align_to for [u8] should never return more than <code>size_of::&lt;T&gt;()</code> bytes in the head or tail slice. anyway, using align_to to determine alignment is probably subpar compared to using, say, align_offset</p>



<a name="240411923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240411923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240411923">(May 27 2021 at 01:44)</a>:</h4>
<p>the need for safe-transmute strikes again</p>



<a name="240412139"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240412139" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240412139">(May 27 2021 at 01:49)</a>:</h4>
<p>not really, this is unaligned and thus wouldn't be safe to transmute</p>



<a name="240422904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240422904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lokathor <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240422904">(May 27 2021 at 05:48)</a>:</h4>
<p>i think if it was easy to make a zeroed array or vec of SimdType, and then safe convert the mutable slice of that into a mutable slice of ElementType and initialize the elements that way, then that would cover a lot of ground</p>



<a name="240428748"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240428748" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240428748">(May 27 2021 at 07:24)</a>:</h4>
<p><span class="user-mention silent" data-user-id="209168">Thom Chiovoloni</span> <a href="#narrow/stream/257879-project-portable-simd/topic/Porting.20benchamark.20examples/near/240406510">said</a>:</p>
<blockquote>
<p>sort of. note that align_to is allowed to return the full slice in the first element, and under miri it will (actually, maybe this has been changed)</p>
</blockquote>
<p>this has been changed a long time ago, to better align miri's default behavior with rustc's real behavior. I don't quite understand why the myth that miri still does this is so persistent, it comes up every other month or so.^^<br>
however, there is still a flag <code>-Zmiri-symbolic-alignment-check</code> that switches back to the old behavior (that flag is better at catching alignment violations than the default behavior).<br>
moreover, if we ever want to support <code>aling_to</code> in <code>const</code>, then it has no choice but to return the full slice in the first element in many cases.</p>



<a name="240428807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240428807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240428807">(May 27 2021 at 07:25)</a>:</h4>
<blockquote>
<p>Part of the frustrating thing about this function is that IMO a "correct" implementation of, say align_to for [u8] should never return more than size_of::&lt;T&gt;() bytes in the head or tail slice. </p>
</blockquote>
<p>This is impossible to implement during const-time, so guaranteeing this means we can never support <code>align_to</code> in CTFE. (I don't have a strong opinion either way here, just pointing out why that guarantee has not been added yet.)</p>



<a name="240514082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240514082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240514082">(May 27 2021 at 18:54)</a>:</h4>
<p>avx512 wants 64-byte alignment IIRC</p>



<a name="240515189"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240515189" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240515189">(May 27 2021 at 19:02)</a>:</h4>
<p>Reading Arm, while they don't seem to require "vector alignment" very much for Neon, they do want <strong>element</strong> alignment.</p>



<a name="240517001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240517001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240517001">(May 27 2021 at 19:14)</a>:</h4>
<p>Okay, actually I just realized the data alignment thing is its own conversation so I am going to split it out into a new thing. Righto.</p>



<a name="240517320"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240517320" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240517320">(May 27 2021 at 19:17)</a>:</h4>
<p>Nice, okay, that makes this easier to read the context of, and now I can ping people and ask for help and not have them have to read a million unrelated questions.</p>



<a name="240522577"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240522577" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240522577">(May 27 2021 at 19:56)</a>:</h4>
<p>Also apparently the x86-64 AVX+ environment is actually pretty loosey-goosey about unaligned accesses:</p>
<blockquote>
<p>According to the AVX spec:<br>
“Most arithmetic and data processing instructions encoded using the VEX prefix and<br>
performing memory accesses have more flexible memory alignment requirements<br>
than instructions that are encoded without the VEX prefix. Specifically,<br>
• With the exception of explicitly aligned 16 or 32 byte SIMD load/store instructions,<br>
most VEX-encoded, arithmetic and data processing instructions operate in<br>
a flexible environment regarding memory address alignment, i.e. VEX-encoded<br>
instruction with 32-byte or 16-byte load semantics will support unaligned load<br>
operation by default. Memory arguments for most instructions with VEX prefix<br>
operate normally without causing #GP(0) on any byte-granularity alignment<br>
(unlike Legacy SSE instructions).”</p>
</blockquote>



<a name="240526501"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240526501" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240526501">(May 27 2021 at 20:26)</a>:</h4>
<p>aarch64 PCS:</p>
<table>
<thead>
<tr>
<th align="left">Type Class</th>
<th align="left">Machine Type</th>
<th align="center">Byte size</th>
<th align="center">Natural Alignment (bytes)</th>
</tr>
</thead>
<tbody>
<tr>
<td align="left">Short vector</td>
<td align="left">64-bit vector</td>
<td align="center">8</td>
<td align="center">8</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">128-bit vector</td>
<td align="center">16</td>
<td align="center">16</td>
</tr>
<tr>
<td align="left">Scalable Vector</td>
<td align="left">VG×64-bit vector of 8-bit elements</td>
<td align="center">VG×8</td>
<td align="center">16</td>
</tr>
<tr>
<td align="left"></td>
<td align="left">VG×64-bit vector of 16-bit elements</td>
<td align="center"></td>
<td align="center"></td>
</tr>
<tr>
<td align="left"></td>
<td align="left">VG×64-bit vector of 32-bit elements</td>
<td align="center"></td>
<td align="center"></td>
</tr>
<tr>
<td align="left"></td>
<td align="left">VG×64-bit vector of 64-bit elements</td>
<td align="center"></td>
<td align="center"></td>
</tr>
<tr>
<td align="left">Scalable Predicate</td>
<td align="left">VG×8-bit predicate</td>
<td align="center">VG</td>
<td align="center">2</td>
</tr>
</tbody>
</table>



<a name="240526983"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240526983" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240526983">(May 27 2021 at 20:30)</a>:</h4>
<p>So, Arm does care about 16 byte alignment for Neon vectors, or at least, would rather you do so. And also 16-byte alignment for Scalable vectors.</p>



<a name="240531093"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240531093" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240531093">(May 27 2021 at 21:01)</a>:</h4>
<p>I really appreciate that Neon and SVE vectors share the same natural alignment. That makes many things simpler. ^^;</p>



<a name="240534208"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240534208" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240534208">(May 27 2021 at 21:26)</a>:</h4>
<p>This is interesting.<br>
<a href="https://www.aes.tu-berlin.de/fileadmin/fg196/publication/old-juurlink/performance_impact_of_misaligned_accesses_in_simd_extensions.pdf">https://www.aes.tu-berlin.de/fileadmin/fg196/publication/old-juurlink/performance_impact_of_misaligned_accesses_in_simd_extensions.pdf</a></p>
<blockquote>
<p>Furthermore, the MMX and SSE implementations using loop peeling technique are up to 1.45 and 1.66 faster than their implementation for addition of two arrays with different sizes, respectively.</p>
</blockquote>



<a name="240535466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240535466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240535466">(May 27 2021 at 21:38)</a>:</h4>
<p>How old is that?</p>



<a name="240535555"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240535555" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240535555">(May 27 2021 at 21:39)</a>:</h4>
<p>Ah yeah, the numbers are measured on pentium 3 and 4, that's probably quite old. My experience here is that this hasn't been true for some time. I think daniel lemire's blog has some numbers here, IIRC (I can't check at the moment)</p>



<a name="240538262"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240538262" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240538262">(May 27 2021 at 22:04)</a>:</h4>
<p>yeah very</p>



<a name="240538491"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240538491" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jubilee <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240538491">(May 27 2021 at 22:07)</a>:</h4>
<p>I think you're thinking of <a href="https://lemire.me/blog/2012/05/31/data-alignment-for-speed-myth-or-reality/">https://lemire.me/blog/2012/05/31/data-alignment-for-speed-myth-or-reality/</a> yeah?</p>



<a name="240539727"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/257879-project-portable-simd/topic/SIMD%20alignment/near/240539727" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Thom Chiovoloni <a href="https://rust-lang.github.io/zulip_archive/stream/257879-project-portable-simd/topic/SIMD.20alignment.html#240539727">(May 27 2021 at 22:23)</a>:</h4>
<p>I remember one about simd but I could be wrong</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>